package com.example.concurrent;

import org.junit.Test;

import java.util.concurrent.atomic.AtomicInteger;

public class TVolatile {
    private volatile int cnt = 0;
    private AtomicInteger atomicInteger = new AtomicInteger(0);
    @Test
    public void test() {
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                for (int j = 0; j < 1000; j++) {
                    cnt++;
                }
            }).start();
        }


        while (Thread.activeCount() > 2)
            Thread.yield();

        System.out.println(cnt);
    }
}
